package com.justinwang4.androidservicedemo.services;

import android.app.IntentService;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;

import androidx.annotation.Nullable;

public class MyIntentBindService extends IntentService {

    public class MyIntentBinder extends Binder {
        MyIntentBindService getService() {
            return MyIntentBindService.this;
        }

        public String getStringInfo() {
            return "MyIntentBinder中的方法";
        }
    }

    private final IBinder binder = new MyIntentBinder();

    public MyIntentBindService() {
        super("MyIntentBindService");
    }

    @Override
    public void onCreate() {
        Log.i("Test", "onCreate has been called!");
        super.onCreate();
    }

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        Log.i("Test", "onBind has been called!");
        return binder;
    }

    @Override
    public boolean onUnbind(Intent intent) {
        Log.i("Test", "onUnbind has been called!");
        return super.onUnbind(intent);
    }

    @Override
    protected void onHandleIntent(@Nullable Intent intent) {
        // won't be called if using bind service
        Log.i("Test", "onHandleIntent has been called!");
    }

    @Override
    public void onDestroy() {
        Log.i("Test", "onDestroy has been called!");
        super.onDestroy();
    }
}
